<?php
/**
* [LupMisAllowedSync]
* 控制器模块/业务名称: lup/testAgent
* 本代码为系统自动生成代码，请根据自己业务进行修改;
* 生成时间: 2022-04-13 10:14:25;
* 版权所有 2020-2022 lizhongwen，并保留所有权利;
* 说明: 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；不允许对程序代码以任何形式任何目的的再发布;
* 作者: 中文Lee;
* 作者主页: http://www.lizhongwen.com;
* 邮箱: 360811363@qq.com;
* QQ: 360811363;
*/
namespace modules\lup\controller;

use modules\lup\service\impl\TestAgentServiceImpl;
use application\core\Request;
use application\core\Result;
use Exception;

class TestAgentController
{

    private $service;

    public function __construct()
    {
        $this->service = new TestAgentServiceImpl();
    }

    /**
     * testAgent列表查询
     * @lupRoleCode lup:testAgent:lists
     * @return array
    */
    public function lists(): array
    {
        return Result::success(false, $this->service->lists(Request::json(), Request::getPagePars()));
    }

    /**
     * testAgent添加
     * @lupRoleCode lup:testAgent:add
     * @return array
    */
    public function add(): array
    {
        try {
            $add = $this->service->add(Request::json());
            if ($add == 0) return Result::fail(false, [], "添加失败");
            return Result::success(true, [], "添加成功");
        } catch (Exception $e) {
            return Result::fail(false, [], $e->getMessage());
        }
    }

    /**
     * testAgent删除
     * @lupRoleCode lup:testAgent:del
     * @return array
    */
    public function del(): array
    {
        try {
            $del = $this->service->del(Request::json());
            if ($del == 0) return Result::fail(false, [], "您未删除任何数据");
            return Result::success(true, [], "删除成功");
        } catch (Exception $e) {
            return Result::fail(false, [], $e->getMessage());
        }
    }

    /**
     * testAgent单条查询
     * @lupRoleCode lup:testAgent:edit
     * @return array
    */
    public function query(): array
    {
        return Result::success(false, $this->service->query(Request::json()));
    }

    /**
     * testAgent编辑
     * @lupRoleCode lup:testAgent:edit
     * @return array
    */
    public function edit(): array
    {
        try {
            $edit = $this->service->edit(Request::json());
            if ($edit == 0) return Result::fail(false, [], "暂未修改任何数据");
            return Result::success(true, [], "修改成功");
        } catch (Exception $e) {
            return Result::fail(false, [], $e->getMessage());
        }
    }
}

